// router/index.jsx
import { createBrowserRouter, createRoutesFromElements, Route } from 'react-router-dom'

// 1. 导入所有组件
import MainLayouts from '../layouts/MainLayout.jsx'
import UserLayouts from '../layouts/UserLayouts.jsx'
import AdminLayout from '../layouts/AdminLayout.jsx'
import Home from '../pages/Home.jsx'
import About from '../pages/About.jsx'
import Login from '../pages/user/Login.jsx'
import Register from '../pages/user/Register.jsx'
import NotFound from '../pages/NotFound.jsx'
import Dict from '../pages/Dict.jsx'
import UserInfo from '../pages/UserInfo.jsx'
import AdminLogin from '../pages/admin/AdminLogin.jsx'
import AdminDashboard from '../pages/admin/AdminDashboard.jsx'
import UserManager from '../pages/admin/UserManager.jsx'
import DictManager from '../pages/admin/DictManager.jsx'
import SystemSettings from '../pages/admin/SystemSettings.jsx'
import AccountSettings from '../pages/admin/AccountSettings.jsx'
import AdminNotFound from '../pages/admin/AdminNotFound.jsx'
// 2. 创建路由配置
const router = createBrowserRouter(
    createRoutesFromElements(
        <Route>
            {/* 主布局路由 */}
            <Route element={<MainLayouts />}>
                <Route index element={<Home />} />
                <Route path="/dict" index element={<Dict />} />
                <Route path="/about" element={<About />} />
                <Route path="/user/info" element={<UserInfo />} />
            </Route>

            {/* 用户布局路由 */}
            <Route path="/user" element={<UserLayouts />}>
                <Route path="login" element={<Login />} />
                <Route path="register" element={<Register />} />
            </Route>

            {/* 管理员相关路由 */}
            <Route path="/admin">
                {/* 管理员登录页面（独立页面） */}
                <Route path="login" element={<AdminLogin />} />

                {/* 管理员布局路由 */}
                <Route element={<AdminLayout />}>
                    <Route path="dashboard" element={<AdminDashboard />} />
                    <Route path="users" element={<UserManager />} />
                    <Route path="templates" element={<DictManager />} />
                    <Route path="settings" element={<SystemSettings />} />
                    <Route path="account-settings" element={<AccountSettings />} />
                </Route>

                {/* 管理员系统的404页面 */}
                <Route path="*" element={<AdminNotFound />} />
            </Route>

            {/* 404 页面 */}
            <Route path="*" element={<NotFound />} />
        </Route>
    )
)

export default router